package com.kds.changzhou.handler;

import com.kds.changzhou.message.outboud.AbstractOutBoundMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 孔德嵩
 */

@Slf4j
public class PackageEncoder extends MessageToByteEncoder {


    private HandlerConfig handlerConfig;

    public PackageEncoder(HandlerConfig handlerConfig) {
        this.handlerConfig = handlerConfig;
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {


        AbstractOutBoundMessage _message = (AbstractOutBoundMessage) msg;

        byte[] message = _message.getMessage();

        log.info("待发送的xml报文:\n\033[31m{}\033[0m",new String(message));
        out.writeBytes(message);

        //ByteBufferUtil.debugAll(out.nioBuffer());
    }


}
